/**
* AutoSWF - Cody Cushing. March 26, 2009
* Copyright (c) 2009 Cody Cushing
* No use restrictions. Maintain this notice in all versions. 
**/

package com.autoswf.core
{
	import flash.events.Event;
	
	import flexunit.framework.TestCase;

	public class TransportTest extends TestCase
	{
		public function TransportTest(methodName:String=null)
		{
			super(methodName);
		}
		
		/** Message is passed through constructor */
		public function testMessage01():void
		{
			var transport:Transport = new Transport("value");
			assertEquals("incorrectly rendered message", "value", transport.message);
		}
		
		/** Message is passed through constructor and path is present */
		public function testMessage02():void
		{
			var transport:Transport = new Transport("value").setPath("path");
			assertEquals("incorrectly rendered message", "value", transport.message);
		}
		
		/** Message is passed through constructor with complex path */
		public function testMessage03():void
		{
			var transport:Transport = new Transport("value").setPath("node1->node2");
			assertEquals("incorrectly rendered message", "value", transport.message);
		}
		
		/** Message is last path node if not passed through constructor. */
		public function testMessage04():void
		{
			var transport:Transport = new Transport().setPath("value");
			assertEquals("incorrectly rendered message", "value", transport.message);
		}
		
		/** Message is last path node if not passed through constructor with other path info. */
		public function testMessage05():void
		{
			var transport:Transport = new Transport().setPath("node1->value");
			assertEquals("incorrectly rendered message", "value", transport.message);
		}
		
		/** Message is last path node if not passed through constructor with complex path info. */
		public function testMessage06():void
		{
			var transport:Transport = new Transport().setPath("node1->node2->value");
			assertEquals("incorrectly rendered message", "value", transport.message);
		}
		
		/** Message can point to an event. */
		public function testMessage07():void
		{
			var event:Event = new Event(Event.CHANGE);
			var transport:Transport = new Transport(event);
			assertStrictlyEquals("incorrectly rendered message", event, transport.message);
		}
		
		/** Message points to event with path. */
		public function testMessageWithEventAndPath():void
		{
			var event:Event = new Event(Event.CHANGE);
			var transport:Transport = new Transport(event).setPath("node1");
			assertStrictlyEquals("event not rendered as message", event, transport.message);
		}
		
		
		/** Dont make this mistake. Path must always use setPath */
		public function testMessage000():void
		{
			var transport:Transport = new Transport("node1->value");
			assertTrue(transport.message == "node1->value"  &&  transport.path == "");
		}
		
		
		
		/** Proposition is message if there is no path information. */
		public function testProposition01():void
		{
			var transport:Transport = new Transport("value");
			assertEquals("incorrectly rendered proposition", "value", transport.proposition);
		}
		
		/** Proposition is path value. */
		public function testProposition02():void
		{
			var transport:Transport = new Transport("value").setPath("node1");
			assertEquals("incorrectly rendered proposition", "node1", transport.proposition);
		}

		/** Proposition is top most path value in path graph. */
		public function testProposition03():void
		{
			var transport:Transport = new Transport("value").setPath("node1->node2");
			assertEquals("incorrectly rendered proposition", "node1", transport.proposition);
		}
		
		/** Proposition can be an event if there is no path information. */
		public function testProposition07():void
		{
			var event:Event = new Event(Event.CHANGE);
			var transport:Transport = new Transport(event);
			assertEquals("incorrectly rendered proposition", event, transport.proposition);
		}
		
		/** Proposition is path when present. */
		public function testProposition08():void
		{
			var event:Event = new Event(Event.CHANGE);
			var transport:Transport = new Transport(event).setPath("node1");
			assertEquals("path not rendered as proposition", "node1", transport.proposition);
		}
		
		

		/** To string prints the message value. */
		public function testToString01():void
		{
			var transport:Transport = new Transport("value");
			assertEquals("Did not print message value as string.", "value", transport.toString());
		}
		
		/** toString prints the path and value. */
		public function testToString02():void
		{
			var transport:Transport = new Transport("value").setPath("node1");
			assertEquals("Did not concat path with message.", "node1->value", transport.toString());
		}

		/** toString plrints complex path and value. */
		public function testToString03():void
		{
			var transport:Transport = new Transport("value").setPath("node1->node2");
			assertEquals("Did not concat path with message.", "node1->node2->value", transport.toString());
		}
		
		/** toString with an event prints the event type. */
		public function testToString07():void
		{
			var transport:Transport = new Transport(new Event(Event.CHANGE));
			assertEquals("Did not print event type.", "change", transport.toString());
		}
		
		/** toString with a path and event prints path and event type*/
		public function testToString08():void
		{
			var transport:Transport = new Transport(new Event(Event.CHANGE)).setPath("node1");
			assertEquals("Did not concat path with event type", "node1->change", transport.toString());
		}

		/** toString prints useless default [object Object] value. */
		public function testToString09():void
		{
			var transport:Transport = new Transport(new Object());
			assertEquals("Did not print useless object.toString() [object Object].", "[object Object]", transport.toString());
		}



		/** addPath pushes a node id into transport's address stack. */		
		public function testAddPath01():void
		{
			var transport:Transport = new Transport("value");
			transport.addPath("node1");
			assertEquals("incorrectly printed string", "node1->value", transport);
		}
		
		/** addPath pushes a node id into transport's address stack. */		
		public function testAddPath02():void
		{
			var transport:Transport = new Transport("value").setPath("node1");
			transport.addPath("node2");
			assertEquals("incorrectly printed string", "node2->node1->value", transport);
		}
		
		
		/** removePath pops a node id from the transport's address stack. */
		public function testRemovePath01():void
		{
			var transport:Transport = new Transport("value").setPath("node1");
			
			transport.removePath();
			assertEquals("failed to render top of chain as proposition", "value", transport);
		}
		
		/** removePath pops a node id from the transport's address stack. */
		public function testRemovePath02():void
		{
			var transport:Transport = new Transport("value").setPath("node1->node2");
			
			transport.removePath();
			assertEquals("failed to render top of chain as proposition", "node2->value", transport);
		}
		
	}
}


